import java.util.*;

/**
 * @author LKQ
 * @date 2022/4/29 10:43
 * @description 排序之后用双指针即可
 */
public class Solution {
    public static void main(String[] args) {

    }
    public int purchasePlans(int[] nums, int target) {
        Arrays.sort(nums);
        int MOD = (int) (1e9 + 7);
        long ans = 0;
        int l = 0, r = nums.length - 1;
        while (l < r) {
            if (nums[l] + nums[r] <= target) {
                ans += r - l;
                ans %= MOD;
                l++;
            }else {
                r--;
            }
        }
        return (int) ans;
    }
}
